-- resonance_hp
-- created by panyl
-- 共鸣血量（同类越多属性越多）

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 翻开格子触发
    trigger = function(who, prop, base)
        local deno = tonumber(prop[3]);
        assert(deno > 0);

        local layer = DungeonM.currentLayer();
        local addHp = math.modf(tonumber(prop[2]) + layer / tonumber(prop[3]));
        for pos = 1, GRID_SIZE do
            repeat
                local grid = DungeonM.getGridByPos(pos);
                local monster = grid.monster;

                -- 如果不是怪物，或者不是同类，或者已经死亡了
                if  not grid:isMonster() or not monster or
                    monster:query("base_class_id") ~= who:query("base_class_id") or
                    monster == who or monster:isDead() then
                    break;
                end

                -- 增加一点加成
                local value = monster.dbase:query("addon_hp", 0) + addHp;
                monster.dbase:set("addon_hp", value);
                EventMgr.fire(event.MONSTER_INFO_UPDATED, {["pos"] = pos, })
            until true;
        end

        return addHp;
    end,

    desc = function(prop)
        local deno = tonumber(prop[3]);
        local layer = DungeonM.currentLayer() or 0;

        local addon = math.modf(1 + layer / deno);

        local desc = string.gsub(desc, "{0}", addon);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
